<?php
/**
 * Object Relational Persistence Mapping Class for table: paraclinique_config
 *
 * @package	com.athena
 * @author	LHV
 */
class ParacliniqueConfig extends ORDataObject {

	/**#@+
	 * Fields of table: paraclinique_config mapped to class members
	 */
	var $paraclinique_config_id		= '';
	var $enum_paraclinic_type		= '';
	var $enum_payment_type		= '';
	var $room_id		= '';
	/**#@-*/


	/**
	 * DB Table
	 */
	var $_table = 'paraclinique_config';

	/**
	 * Primary Key
	 */
	var $_key = 'paraclinique_config_id';

	/**
	 * Internal Name
	 */
	var $_internalName = 'ParacliniqueConfig';

	/**
	 * Handle instantiation
	 */
	function __construct() {
		parent::ORDataObject();
	}
	/**
	 * get configuration of a given $enumParaClinicType.
	 * @param $enumParaClinicType
	 * @return array(enum_payment_type, room_id)
	 */
	public function getParaclinicConfig($enumParaClinicType) {
		$ds =& new Datasource_sql();
		$paraClinicType = Utils::getEnumKey(EnumerationConstant::PARACLINIC_TYPE, $enumParaClinicType);
        $sql = array(
            'cols'  => "enum_payment_type, room_id",
            'from'  => "$this->_table",
            'where' =>   "enum_paraclinic_type ='" . $paraClinicType ."'",
            );
        $ds->setup($this->_db, $sql);
        $result = $ds->toArray();
        if (empty($result)) {
        	return null;
        }
        return $result[0];
	}
	
    public function listParaclinicConfig() {
        $ds =& new Datasource_sql();
        $sql = array(
            'cols'  => "enum_payment_type, room_id, enum_paraclinic_type",
            'from'  => "$this->_table"            
            );
        $ds->setup($this->_db, $sql);
        $result = $ds->toArray();
        $arr = array();
        foreach ($result as $item) {
            $arr[$item['enum_paraclinic_type']] = 
            array(
            'room_id'           =>  $item['room_id'],
            'enum_payment_type' =>  $item['enum_payment_type']
            );
        }        
        return $arr;
    }
    private function delete($enumParaclinicType) {
        $sql = "DELETE from $this->_table WHERE enum_paraclinic_type='" . $enumParaclinicType . "'";
        $this->_execute($sql);        
    }    
    public function saveConfig($data = array()) {
        $this->delete($data['enum_paraclinic_type']);
        $this->populateArray($data);
        $this->persist();
        return $this->get_id();
    }


	public function getRadiologyTypes() {
        $paraTypes   =     Utils::getEnumArrayKey(EnumerationConstant::PARACLINIC_TYPE);
        $ret         =     array();
        foreach ($paraTypes as $key => $value) {
            if($key == Utils::getEnumKey(EnumerationConstant::PARACLINIC_TYPE,
                        EnumerationConstant::PARACLINIC_LAB)) {
                unset($paraTypes[$key]);
            }
        }
        return $paraTypes;
	}
}
?>
